<!-- 我的组件 -->
<template>
  <div class="mv-container">
    <header>猫眼电影</header>
    <van-image
      class="logo"
      width="2rem"
      height="2rem"
      fit="cover"
      src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fmpimg.cnfol.com%2Fueditor%2F1552639566309014.jpg&refer=http%3A%2F%2Fmpimg.cnfol.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653634841&t=0309dadebf21ca03648f2347ea55e153"
    />
    <van-form @submit="onSubmit" validate-first @failed="onFailed">
      <van-field
        v-model="username"
        name="用户名"
        label="手机号"
        placeholder="请输入手机号"
        :rules="[{ pattern1, required: true, message: '手机号格式错误' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '密码格式错误' }]"
      />
      <div @click="goToPersonal">
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >登录</van-button
          >
        </div>
      </div>
    </van-form>
    <div class="text">
      <input class="check" type="checkbox" checked="checked" name="" id="" />
      <span>我已阅读并同意</span>
      <span class="agree">《猫眼用户服务协议》《隐私政策》</span>
      <div class="phone">
        客服电话:
        <span class="number">1010-5335</span>
      </div>
      <div class="tip">未注册的手机号将自动生成新账号</div>
    </div>
    <!-- <div class="form-group form-inline">
      <label for="username">登录名称</label>
      <input
        type="text"
        class="form-control ml-2"
        id="username"
        placeholder="请输入登录名称"
        autocomplete="off"
        v-model.trim="username"
      />
    </div>
    <div class="form-group form-inline">
      <label for="password">登录密码</label>
      <input
        type="password"
        class="form-control ml-2"
        id="password"
        placeholder="请输入登录密码"
        v-model.trim="password"
      />
    </div> -->
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import Vue from "vue";
import { Form } from "vant";
import { Field } from "vant";
import { Checkbox, CheckboxGroup } from "vant";
import { Image as VanImage } from "vant";

Vue.use(VanImage);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Form);
Vue.use(Field);
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    return {
      username: "",
      password: "",
      checked: true,
      pattern1:
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
      // pattern2: /^[0-9]{6,18}$"/,
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
    },
    goToPersonal: function () {
      if (this.username === "13433480101" && this.password === "123456") {
        // 登录成功
        // 1. 存储 token 键,值
        localStorage.setItem("token", "ranger41");
        // 2. 跳转到后台主页
        this.$router.push("/personal");
      } else {
        // 登录失败，清空
        alert("用户名或密码错误");
        localStorage.removeItem("token");
      }
    },
    onFailed(errorInfo) {
      console.log("failed", errorInfo);
    },
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
@import url("@/assets/border.less");
.mv-container {
  header {
    height: 0.45rem;
    line-height: 0.45rem;
    color: white;
    font-weight: bold;
    background-color: #e54847;
    text-align: center;
    font-size: 0.16rem;
  }
  .logo {
    margin-top: 0.1rem;
    margin-left: 0.875rem;
  }
  .van-button--info {
    color: #fff;
    background-color: #e54847;
    border: 1px solid #e54847;
  }
  .van-cell {
    margin-top: 0.2rem;
  }
  .text {
    // width: 80%;
    text-align: center;
    margin-top: 0.4rem;
    .agree {
      color: #df2d2d;
    }
    .number {
      color: #df2d2d;
    }
    .tip {
      padding: 0.2rem 0;
      color: #999999;
    }
  }
  .check {
    margin-right: 0.1rem;
  }
}
</style>

